<!DOCTYPE html>
<html lang="en">
<head>
    <meta  http-equiv="content-type" content="text/html" charset="utf-8"/>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        /**
         *
         *
        var name = "xiao a";
        var obj = {
            name:'xiao b',
            getName:function(){
                return function(){
                    return this.name;
                }
            }
        }
        alert(obj.getName()());//返回xiao a

        var a = obj.getName();
        a(); */

        /**
         *
         * @type {string}

        var name = "xiao a";
        var obj = {
            name:'xiao b',
            getName:function(){
                //this总是指向调用者
               var o = this;
                return function(){
                    return o.name;
                }
            }
        }
        alert(obj.getName()());
        var k = obj.getName();
        k();//返回xiao b   因为this被保存起来了  */

        /**
         * 真正的闭包例子
         */
        function f(x){
            var temp = x;
            return function(x){
                temp+=x;            //temp不会被回收
                alert(temp);
            }
        }
        var a = f(50);
        alert(a);//函数的结构体
        a(5);//55
        a(10);//65
        a(15);//80


    </script>
</head>
<body>

</body>
</html>